import http from '../api/http'
//获取帖子的api
//  /bbc  ===  http://59.111.92.205:8088

//1、帖子列表 （带参数查询，不带参数返回全部）
function getNoteList(postsId="",title=""){
    const params = new URLSearchParams();
    params.append("postsId", postsId);
    params.append("title", title);
    const url = 'api/bbs/bbsPosts/open/list'
    return http.post(url,params)
}
//2、帖子详情  （id 必须带）
function  getNodeDetail(postsId) {
    const url = `api/bbs/bbsPosts/open/detail/${postsId}`
    return http.get(url)
}

//3、专题列表  (带参数返回固定专题，不带参数返回全部)
function getCategory(categoryId=""){
    const params = new URLSearchParams();
    params.append("categoryId", categoryId);
    const url = '/api/bbs/bbsCategory/open/list'
    return http.post(url,params)
}

// 4、我参与的
function getMyJoin(){
    const params = new URLSearchParams();
    const url = '/api/bbs/bbsPosts/join/list'
    return http.post(url,params)
}
//5、删除评论
function delComment(ids){
    const params = new URLSearchParams();
    params.append("ids", ids);
    const url = '/api/bbs/bbsComment/site/remove'
    return http.post(url,params)
}
//6、创建帖子
function creatNode(categoryId,title,intro,coverImgUrl){
    const params = new URLSearchParams();
    params.append("categoryId", categoryId);
    params.append("title", title);
    params.append("intro", intro);
    params.append("coverImgUrl", coverImgUrl);
    const url = '/api/bbs/bbsPosts/site/add'
    return http.post(url,params)
}
//7、回复列表  （评论id）
function gitAnswerList(parentId){
    const params = new URLSearchParams();
    params.append("parentId", parentId);
    const url = '/api/bbs/bbsComment/open/reply/list'
    return http.post(url,params)
}
//8、评论列表  (帖子id)
function gitCommentList(postsId=""){
    const params = new URLSearchParams();
    params.append("postsId", postsId);
    const url = '/api/bbs/bbsComment/open/list'
    return http.post(url,params)
}
//9、回复评论
function commentAnswer(postsId,parentId,commentContent){
    const params = new URLSearchParams();
    params.append("postsId", postsId);
    params.append("parentId", parentId);
    params.append("commentContent", commentContent);
    const url = '/api/bbs/bbsComment/site/reply/add'
    return http.post(url,params)
}

//10、发表评论
function postComment(postsId,commentContent){
    const params = new URLSearchParams();
    params.append("postsId", postsId);
    params.append("commentContent", commentContent);
    const url = '/api/bbs/bbsComment/site/add'
    return http.post(url,params)
}
//11、修改帖子
function reviseNode(postsId,title,categoryId=""){
    const params = new URLSearchParams();
    params.append("postsId", postsId);
    params.append("title", title);
    params.append("categoryId", categoryId);
    const url = '/api/bbs/bbsPosts/site/edit'
    return http.post(url,params)
}
//12、删除帖子
function delNode(ids){
    const params = new URLSearchParams();
    params.append("ids", ids);
    const url = '/api/bbs/bbsPosts/site/remove'
    return http.post(url,params)
}
export {delNode,reviseNode,postComment,commentAnswer,gitCommentList,gitAnswerList,getNoteList,getNodeDetail,getCategory,getMyJoin,delComment,creatNode}

//登录有关接口

//登录
function login(username,password,rememberMe){
    const params = new URLSearchParams();
    params.append("username", username);
    params.append("password", password);
    params.append("rememberMe", rememberMe);
    const url = '/api/login'
    return http.post(url,params)
}
//短信验证
function  phoneCade(mobile) {
    const url = `/api/short-message/vcode/${mobile}`
    return http.get(url)
}
//注册
function registry(loginName,code,phonenumber,password,userName,sex=2,remark=""){
    const params = new URLSearchParams();
    params.append("loginName", loginName);
    params.append("code", code);
    params.append("phonenumber", phonenumber);
    params.append("password", password);
    params.append("userName", userName);
    params.append("sex", sex);
    params.append("remark", remark);
    const url = '/api/registry'
    return http.post(url,params)
}
//查看个人信息
function  userInfo() {
    const url = `/api/login-user/info`
    return http.get(url)
}
//忘记密码
function forgotPassword(loginName,code,phonenumber,password){
    const params = new URLSearchParams();
    params.append("loginName", loginName);
    params.append("code", code);
    params.append("phonenumber", phonenumber);
    params.append("password", password);
    const url = '/api/password/forget'
    return http.post(url,params)
}
// 修改个人信息
function changeInfo(userName,sex,email=""){
    const params = new URLSearchParams();
    params.append("userName", userName);
    params.append("sex", sex);
    params.append("email", email);
    const url = '/api/system/user/profile/update'
    return http.post(url,params)
}
//上传头像
function changeAvatarImg(avatarfile){
    const params = new FormData();
    // let config = {
    //     headers: {'Content-Type': 'multipart/form-data'}
    // }
    params.append("avatarfile", avatarfile);
    const url = '/api/system/user/profile/update/avatar/nos'
    return http.post(url,params)
}
//上传图片    fileUseForEnum做成下拉列表 BBS/DEFAULT/RICH_TEXT/AVATAR/CMS/SHOP/BBS
function uploadImg(file,fileUseForEnum='BBS'){
    const params = new FormData();
    params.append("file", file);
    params.append("fileUseForEnum", fileUseForEnum);
    const url = '/api/nos/upload/image'
    return http.post(url,params)
}
//退出登录
function  logout() {
    const url = `/api/logout`
    return http.get(url)
}
export {logout,uploadImg,changeAvatarImg,changeInfo,forgotPassword,userInfo,login,phoneCade,registry}